package com.tjh.spring5.testdemo;

import com.tjh.spring5.autowire.Emp;
import com.tjh.spring5.bean.Orders;
import com.tjh.spring5.collectiontype.Book;
import com.tjh.spring5.collectiontype.Course;
import com.tjh.spring5.collectiontype.Stu;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Create by koala on 2021-02-16
 */
public class TestSpring5Day12 {

    //day12
    @Test
    public void testCollection1() {
        ApplicationContext context =
                new ClassPathXmlApplicationContext("beanday12.xml");
        Stu stu = context.getBean("stu", Stu.class);
        stu.test();
    }

    //day13
    @Test
    public void testCollection2() {
        ApplicationContext context =
                new ClassPathXmlApplicationContext("beanday13.xml");
        Book book = context.getBean("book", Book.class);
        book.test();
    }

    //day14
    @Test
    public void test3() {
        ApplicationContext context =
                new ClassPathXmlApplicationContext("beanday14.xml");
        Course course = context.getBean("myBean", Course.class);
        System.out.println(course);
    }

    //day15
    @Test
    public void testCollection3() {
        ApplicationContext context =
                new ClassPathXmlApplicationContext("beanday15.xml");
        Book book1 = context.getBean("book", Book.class);
        Book book2 = context.getBean("book", Book.class);

        System.out.println(book1 == book2);
    }

    //day16
    @Test
    public void testBean3() {
        /*ApplicationContext context =
                new ClassPathXmlApplicationContext("bean4.xml");*/
        ClassPathXmlApplicationContext context =
                new ClassPathXmlApplicationContext("beanday16.xml");
        System.out.println("第四步 获取创建bean实例对象");
        Orders orders = context.getBean("orders", Orders.class);

        //手动让bean实例销毁
        context.close();
    }

    //day17
    @Test
    public void test4() {
        ApplicationContext context =
                new ClassPathXmlApplicationContext("beanday17.xml");
        Emp emp = context.getBean("emp", Emp.class);
        System.out.println(emp);
    }
}
